3 use Wikimedia\TestingAccessWrapper
;
10 * @covers SpecialWatchlist
12 class SpecialWatchlistTest
extends SpecialPageTestBase
{
13 public function setUp() {
16 $this->setTemporaryHook(
17 'ChangesListSpecialPageQuery',
22 'wgDefaultUserOptions',
24 'extendwatchlist' => 1,
25 'watchlistdays' => 3.0,
26 'watchlisthideanons' => 0,
27 'watchlisthidebots' => 0,
28 'watchlisthideliu' => 0,
29 'watchlisthideminor' => 0,
30 'watchlisthideown' => 0,
31 'watchlisthidepatrolled' => 0,
32 'watchlisthidecategorization' => 1,
33 'watchlistreloadautomatically' => 0,
34 'watchlistunwatchlinks' => 0,
40 * Returns a new instance of the special page under test.
44 protected function newSpecialPage() {
45 return new SpecialWatchlist();
48 public function testNotLoggedIn_throwsException() {
49 $this->setExpectedException( UserNotLoggedIn
::class );
50 $this->executeSpecialPage();
53 public function testUserWithNoWatchedItems_displaysNoWatchlistMessage() {
54 $user = new TestUser( __METHOD__
);
55 list( $html, ) = $this->executeSpecialPage( '', null, 'qqx', $user->getUser() );
56 $this->assertContains( '(nowatchlist)', $html );
60 * @dataProvider provideFetchOptionsFromRequest
62 public function testFetchOptionsFromRequest( $expectedValues, $preferences, $inputParams ) {
63 $page = TestingAccessWrapper
::newFromObject(
64 $this->newSpecialPage()
67 $context = new DerivativeContext( $page->getContext() );
69 $fauxRequest = new FauxRequest( $inputParams, /* $wasPosted= */ false );
70 $user = $this->getTestUser()->getUser();
72 foreach ( $preferences as $key => $value ) {
73 $user->setOption( $key, $value );
76 $context->setRequest( $fauxRequest );
77 $context->setUser( $user );
78 $page->setContext( $context );
80 $page->registerFilters();
81 $formOptions = $page->getDefaultOptions();
82 $page->fetchOptionsFromRequest( $formOptions );
84 $this->assertArrayEquals(
86 $formOptions->getAllValues(),
87 /* $ordered= */ false,
92 public function provideFetchOptionsFromRequest() {
93 // $defaults and $allFalse are just to make the expected values below
94 // shorter by hiding the background.
96 $page = TestingAccessWrapper
::newFromObject(
97 $this->newSpecialPage()
100 $page->registerFilters();
102 // Does not consider $preferences, just wiki's defaults
103 $wikiDefaults = $page->getDefaultOptions()->getAllValues();
105 $allFalse = $wikiDefaults;
107 foreach ( $allFalse as $key => &$value ) {
108 if ( $value === true ) {
113 // This is not exposed on the form (only in preferences) so it
114 // respects the preference.
115 $allFalse['extended'] = true;
130 // First two same as prefs
134 // Second two overriden
135 'hideanons' => false,
137 'userExpLevel' => 'registered'
140 'watchlisthideminor' => 1,
141 'watchlisthidebots' => 0,
143 'watchlisthideanons' => 1,
144 'watchlisthideliu' => 0,
152 // Defaults/preferences for form elements are entirely ignored for
153 // action=submit and omitted elements become false
156 'hideminor' => false,
158 'hideanons' => false,
160 'userExpLevel' => 'unregistered'
163 'watchlisthideminor' => 0,
164 'watchlisthidebots' => 1,
166 'watchlisthideanons' => 0,
167 'watchlisthideliu' => 1,
172 'action' => 'submit',